package org.ruizhijie.util;

import java.io.UnsupportedEncodingException;

public class CharUtil {
	public static final String bytesToHexString(byte[] b) {
		StringBuffer sb = new StringBuffer(b.length);
		String sTemp;
		for (int i = 0; i < b.length; i++) {
			sTemp = Integer.toHexString(0xFF & b[i]);
			if (sTemp.length() < 2)
				sb.append(0);
			sb.append(sTemp.toUpperCase());
		}
		return sb.toString();
	}

	public static byte[] sendIdkVoiceData(String info) {
		byte[] basc = null;
		try {
			basc = info.getBytes("GB18030");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		int bcount = basc.length;
		if (bcount > 255)
			bcount = 255;
		byte[] datas = new byte[bcount + 4];
		datas[0] = (byte) 0xaa;
		datas[1] = (byte) 0xff;
		datas[2] = 5;
		datas[3] = (byte) bcount;

		for (int i = 0; i < bcount; i++)
			datas[4 + i] = basc[i];

		return datas;

	}
}
